package collection;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;

/**
 * author : yeswater
 * date : 2023/7/17
 *
 * collections 工具类 排序
 */

public class CollectionsTest {

    @Test
    public void test() {
        ArrayList list = new ArrayList();
        list.add(2);
        list.add(1);
        list.add(3);


        Collections.sort(list, (o1, o2) -> {
            if(o1 instanceof Integer) {
                Integer i1 = (Integer) o1;
                Integer i2 = (Integer) o2;

                return i1 - i2;
            }
            throw new RuntimeException("类型不匹配");
        });

        Collections.<Integer>sort(list, (o1, o2) -> {
            return o2 - o1;
        });

        System.out.println(list);

    }

}
